# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=rst2pdf
pkgver=0.100
pkgrel=3
pkgdesc="Use a text editor. Make a PDF"
arch=(any)
url="https://github.com/rst2pdf/rst2pdf"
license=(MIT)
depends=(
  python
  python-docutils
  python-importlib-metadata
  python-jinja
  python-packaging
  python-pillow
  python-pygments
  python-reportlab
  python-smartypants
  python-yaml
)
makedepends=(
  python-build
  python-installer
  python-setuptools-scm
  python-wheel
)
# TODO: package python-xhtml2pdf
# https://github.com/xhtml2pdf/xhtml2pdf/issues/560
checkdepends=(
  graphviz
  plantuml
  python-aafigure
  python-matplotlib
  python-pytest
  python-pymupdf
  python-sphinx
  python-svglib
)
# TODO: package python-xhtml2pdf
optdepends=(
  'plantuml: for UML diagram support'
  'python-aafigure: for ASCII image support'
  'python-pyphen: for hyphenation support'
  'python-matplotlib: for math support'
  'python-sphinx: for sphinx support'
  'python-svglib: for SVG support'
)
source=($pkgname-$pkgver.tar.gz::https://github.com/$pkgname/$pkgname/archive/refs/tags/$pkgver.tar.gz)
sha512sums=('ad08629ddec84c50463da726caba71ee3045a37a62fdd58f33afb4ecabeae1b5b0b5ca139d11996ba733f9e03f893e0e7108cd9cbbdd6f0ec9b1c81056b9c3da')
b2sums=('bbc448e8a1fa6a50dc9883a0466de1ec6f0f99582a0d968733f2801766fa1ee2793c84186887144ebd75b79f757689248cbb3334716ceddb80dc2bdc73f729ed')

build() {
  cd $pkgname-$pkgver
  export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
  python -m build --wheel --no-isolation
}

check() {
  local pytest_options=(
    -vv
    # https://github.com/rst2pdf/rst2pdf/issues/1067
    --deselect tests/input/test_raw_html.rst::test_raw_html
  )
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $pkgname-$pkgver
  python -m installer --destdir="test_dir" dist/*.whl

  export PYTHONPATH="$PWD/test_dir/$site_packages:$PYTHONPATH"
  export PATH="$PWD/test_dir/usr/bin:$PATH"
  pytest "${pytest_options[@]}"
}

package() {
  cd $pkgname-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 {CHANGES,MAINTAINERS,README}.rst -t "$pkgdir/usr/share/doc/$pkgname/"
  install -vDm 644 LICENSE.txt -t "$pkgdir/usr/share/licenses/$pkgname/"
}
